package com.ruoyi.patrol.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PatrolPlan;
import com.ruoyi.patrol.service.IPatrolPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡查计划Controller
 * 
 * @author yepanpan
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/patrol/plan")
public class PatrolPlanController extends BaseController
{
    @Autowired
    private IPatrolPlanService patrolPlanService;

    /**
     * 查询巡查计划列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatrolPlan patrolPlan)
    {
        startPage();
        List<PatrolPlan> list = patrolPlanService.selectPatrolPlanList(patrolPlan);
        return getDataTable(list);
    }

    /**
     * 导出巡查计划列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:plan:export')")
    @Log(title = "巡查计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatrolPlan patrolPlan)
    {
        List<PatrolPlan> list = patrolPlanService.selectPatrolPlanList(patrolPlan);
        ExcelUtil<PatrolPlan> util = new ExcelUtil<PatrolPlan>(PatrolPlan.class);
        util.exportExcel(response, list, "巡查计划数据");
    }


    /**
     * 获取巡查计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(patrolPlanService.selectPatrolPlanById(id));
    }

    /**
     * 新增巡查计划
     */
    @PreAuthorize("@ss.hasPermi('patrol:plan:add')")
    @Log(title = "巡查计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PatrolPlan patrolPlan)
    {
                patrolPlan.setCreateBy(getUsername());
        return toAjax(patrolPlanService.insertPatrolPlan(patrolPlan));
    }

    /**
     * 修改巡查计划
     */
    @PreAuthorize("@ss.hasPermi('patrol:plan:edit')")
    @Log(title = "巡查计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PatrolPlan patrolPlan)
    {
                patrolPlan.setUpdateBy(getUsername());
        return toAjax(patrolPlanService.updatePatrolPlan(patrolPlan));
    }

    /**
     * 删除巡查计划
     */
    @PreAuthorize("@ss.hasPermi('patrol:plan:remove')")
    @Log(title = "巡查计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(patrolPlanService.deletePatrolPlanByIds(ids));
    }
}
